package com.cmcc.zysoft.infocollection.service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.cmcc.zysoft.infocollection.dao.HeadshipPcDao;
import com.cmcc.zysoft.infocollection.model.Headship;
import com.starit.common.dao.hibernate.HibernateBaseDao;
import com.starit.common.dao.service.BaseServiceImpl;
import com.starit.common.dao.support.Pagination;

/**
 * @author 喻金龙
 * <br />邮箱: yu.jinlong@ustcinfo.com
 * <br />描述: HeadshipPcService.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-9-7 下午2:33:01
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Service
public class HeadshipPcService extends BaseServiceImpl<Headship, String> {
	@Resource
	private HeadshipPcDao headshipPcDao;
	
	@Override
	public HibernateBaseDao<Headship, String> getHibernateBaseDao() {
		return headshipPcDao;
	}

	/**
	 * 获取所有岗位信息.
	 * @param page
	 * @param rows
	 * @param companyId 企业ID
	 * @param keyword 搜索关键字
	 * @return Map<String, Object>
	 */
	public Map<String, Object> getAllHeadship(int page, int rows, String companyId, String keyword) {
		return this.headshipPcDao.getAllHeadship(page, rows, companyId, keyword);
	}
	
	/**
	 * 判断岗位名是否同名
	 * @param headshipName
	 * @return true表示同名   false表示不同名
	 */
	public boolean isHeadshipNameEqual(String companyId , String headshipName,String headshipId){
		return this.headshipPcDao.isHeadshipNameEqual(companyId, headshipName, headshipId);
	}
	
	/**
	 * 保存岗位信息
	 * @param headship角色对象
	 */
	public void saveHeadship(Headship headship) {
		 this.headshipPcDao.saveHeadship(headship);
	}
	
	/**
	 * 根据岗位id获取岗位信息
	 * @param headshipId 岗位id
	 * @return
	 */
	public Headship getHeadship(String headshipId) {
		return this.headshipPcDao.getHeadship(headshipId);
	}
	
	/**
	 * 修改岗位信息
	 * @param headship岗位对象
	 */
	public void updateHeadship(Headship headship) {
		this.headshipPcDao.updateHeadship(headship);
	}

	/**
	 * 根据岗位id删除岗位信息
	 * @param headshipId 岗位id
	 */
	public void deleteHeadship(String headshipId) {
		this.headshipPcDao.deleteHeadship(headshipId);
	}
	
	/**
	 * 根据查询条件获取岗位信息
	 * @param headshipName岗位名称
	 * @param page
	 * @param rows
	 * @return
	 */
	public Pagination<Object> getHeadshipByCondition(String headshipName, int page,
			int rows, String companyId) {
		return this.headshipPcDao.getHeadshipByCondition(headshipName, page, rows, companyId);
	}
	
	/**
	 * 根据岗位名称获取岗位信息.
	 * @param companyId 企业ID
	 * @param headshipName 岗位名称
	 * @return String(岗位ID)
	 */
	public String getHeadshipId(String companyId, String headshipName) {
		List<Map<String, Object>> list = this.headshipPcDao.getHeadshipId(companyId, headshipName);
		if(null != list && !list.isEmpty()) {
			return list.get(0).get("headship_id").toString();
		} else {
			return "";
		}
	}
	
	/**
	 * 添加岗位.
	 * @param userId 当前用户ID-添加人
	 * @param companyId 企业ID
	 * @param headshipName 岗位名称
	 * @return String(岗位ID)
	 */
	@Transactional
	public String addHeadship(String userId, String companyId, String headshipName) {
		Headship headship = new Headship();
		headship.setCompanyId(companyId);
		headship.setHeadshipName(headshipName);
		headship.setHeadshipLevel("1");
		headship.setCreateMan(userId);
		headship.setCreateTime(new Date());
		headship.setStatus("0");
		headship.setDelFlag("0");
		return this.headshipPcDao.save(headship);
	}
}